
#include <BOpenGL>
#include "member_BPicker.h"
#include "member_BGroup.h"
#include "member_BNode.h"
#include "member_BShape.h"
#include "member_BPicker.h"
#include "member_BPickHit.h"
#include "member_BBillboard.h"

using namespace BWE;

member_BPicker::member_BPicker(BPicker* picker)
{
	boss = picker;
	scene = 0;
	group = 0;
	node = 0;
	shape = 0;
	hitNums = 1;
}
member_BPicker::~member_BPicker()
{

}

void member_BPicker::enter(const BLine& line, BGroup* group)
{
	if (boss->ignore(group))
		return;

	const BSpace& space = group->space();
	if (!space.contain(line.begin()) && !space.contain(line.end()))
	{
		if (false == line.intersect(space))
			return;
	}

	this->group = group;
	boss->pick(line, group);
	this->group = 0;
}
void member_BPicker::enter(const BLine& line, BNode* node)
{
	if (boss->ignore(node))
		return;

	BMatrix matrix = node->matrix().inverse();
	BLine localLine = line * matrix;

	const BBox& box = node->box();
	if (!box.contain(localLine.begin()) && !box.contain(localLine.end()))
	{
		if (false == localLine.intersect(box))
			return;
	}

	this->node = node;
	boss->pick(localLine, node);
	this->node = 0;
	return;
}
void member_BPicker::enter(const BLine& line, BShape* shape)
{
	if (boss->ignore(shape))
		return;

	BMatrix matrix = shape->matrix().inverse();
	BLine localLine = line * matrix;

	BBox box = shape->box();
	if (!box.contain(localLine.begin()) && !box.contain(localLine.end()))
	{
		if (false == localLine.intersect(box))
			return;
	}

	this->shape = shape;
	boss->pick(localLine, shape);
	this->shape = 0;
}

